package com.huawei.esdk.tp.northcommu.cxf.professional;

import java.util.List;
import org.apache.log4j.Logger;
import com.huawei.esdk.platform.common.SDKResult;
import com.huawei.esdk.platform.common.exception.SDKException;
import com.huawei.esdk.tp.business.professional.orgamgr.OrgaManagerService;
import com.huawei.esdk.tp.common.ErrInfo;
import com.huawei.esdk.tp.domain.model.bean.OrganizationItem;
import com.huawei.esdk.tp.northcommu.cxf.professional.convert.TPProfessionalOrgaMgrConvert;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryOrganizationEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryOrganizationExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.TPProfessionalOrgaMgr;

public class TPProfessionalOrgaMgrImpl implements TPProfessionalOrgaMgr
{
    private OrgaManagerService orgaManagerService;
    
    private TPProfessionalOrgaMgrConvert tpProfessionalOrgaMgrConvertService;
    
    private static final Logger LOGGER = Logger.getLogger(TPProfessionalOrgaMgrImpl.class);
    
    public OrgaManagerService getOrgaManagerService()
    {
        return orgaManagerService;
    }
    
    public void setOrgaManagerService(OrgaManagerService orgaManagerService)
    {
        this.orgaManagerService = orgaManagerService;
    }
    
    public TPProfessionalOrgaMgrConvert getTpProfessionalOrgaMgrConvertService()
    {
        return tpProfessionalOrgaMgrConvertService;
    }
    
    public void setTpProfessionalOrgaMgrConvertService(TPProfessionalOrgaMgrConvert tpProfessionalOrgaMgrConvertService)
    {
        this.tpProfessionalOrgaMgrConvertService = tpProfessionalOrgaMgrConvertService;
    }
    
    @Override
    public QueryOrganizationExResponse queryOrganizationEx(QueryOrganizationEx parameters)
    {
        QueryOrganizationExResponse response = new QueryOrganizationExResponse();
        try
        {
            if (null == parameters)
            {
                response.setResultCode(ErrInfo.SDK_PARAM_NOT_COMPLETE_ERRORCODE);
                return response;
            }
            
            SDKResult<List<OrganizationItem>> organizations = orgaManagerService.queryOrganization();
            
            response = tpProfessionalOrgaMgrConvertService.queryOrganizationExModal2Soap(organizations);
        }
        catch (SDKException ex)
        {
            LOGGER.error("queryOrganizationEx method error", ex);
            response.setResultCode((int)ex.getSdkErrCode());
        }
        catch (Exception e)
        {
            LOGGER.error("queryOrganizationEx method error", e);
            response.setResultCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }
        return response;
    }
    
}
